package com.pangu.interfaces.openfeign.fallback;

import com.pangu.interfaces.proxy.BaseFallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.lang.reflect.ParameterizedType;

/**
 * @author Linbizhao
 * @description:
 * @since 2023/11/17 18:46
 */
@Slf4j
public class BaseOpenFeignFallback<T> extends BaseFallbackFactory<T> implements FallbackFactory<T> {

    /**
     * 获取对应的对象类型，用于生成动态代理对象
     */
    public <T> Class<T> getClazz() {
        Class<T> tClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        return tClass;
    }

    @Override
    public T create(Throwable cause) {
        return super.createFallbackFactory(cause, getClazz());
    }
}
